{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 拓展 TVM C++ 功能\n",
    "\n",
    "在 C++ 中定义加法算子："
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "````{tab-set-code}\n",
    "```{literalinclude} ../cpp/sym_add/src/tvm_ext.cc\n",
    ":language: c++\n",
    "```\n",
    "\n",
    "```{literalinclude} ../cpp/sym_add/Makefile\n",
    ":language: Makefile\n",
    "```\n",
    "````"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "编译："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "rm -rf outputs/*\n",
      "/media/pc/data/lxw/envs/anaconda3x/envs/xxx/bin/x86_64-conda-linux-gnu-c++ -std=c++17 -O2 -fPIC -I/media/pc/data/board/arria10/lxw/tasks/tvm-ai/include -I/media/pc/data/board/arria10/lxw/tasks/tvm-ai/3rdparty/dmlc-core/include -I/media/pc/data/board/arria10/lxw/tasks/tvm-ai/3rdparty/dlpack/include -Iinclude -DDMLC_USE_LOGGING_LIBRARY=\\<tvm/runtime/logging.h\\> -shared -o outputs/libs/libtvm_ext.so src/tvm_ext.cc -ldl -pthread -L/media/pc/data/board/arria10/lxw/tasks/tvm-ai/build\n"
     ]
    }
   ],
   "source": [
    "!cd ../cpp/sym_add && make clean && make"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "查看编译后的动态库："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "libtvm_ext.so\n"
     ]
    }
   ],
   "source": [
    "!ls ../cpp/sym_add/outputs/libs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
